<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en" class="no-js"> <!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <include file="Public:meta"/>
    <link rel="stylesheet" type="text/css" href="__TMPL__Public/plugins/bootstrap-fileupload/bootstrap-fileupload.css"/>
    <link rel="stylesheet" type="text/css" href="__TMPL__Public/css/goods.css"/>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed">
<include file="Public:header"/>
<!-- BEGIN CONTAINER -->
<div class="page-container">
    <include file="Public:sidebar"/>
    <!-- BEGIN PAGE -->
    <div class="page-content">
        <div class="container-fluid">
            <div class="row-fluid">
                <!-- begin BCN -->
                <div class="row-fluid">
                    <div class="span12"><ul class="breadcrumb"><li><i class="icon-home"></i><a onfocus="blurLink(this);" href="{:U('Index/index')}">首页</a>&nbsp;<span class="icon-angle-right"></span>&nbsp;</li><li><a onfocus="blurLink(this);" href="{:U(CONTROLLER_NAME . '/index', 'kept=1')}">{$ParentPageName|default="未命名"}</a>&nbsp;<span class="icon-angle-right"></span>&nbsp;</li><li>{$PageName|default="未命名"}</li></ul></div>
                </div>
                <!-- end BCN -->
            </div>
            <div class="row-fluid white">
                <div class="span12">
                    <form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
                        {$autoFields}
                        <input type='hidden' name="del_ids" />
                        <div class="form-button">
                            <button type="submit" class="btn blue">保存数据 <i class="icon-save"></i></button>
                            <a href="{:U(CONTROLLER_NAME . '/index', 'kept=1')}" class="btn">返回列表 <i class="icon-share-alt"></i></a>
                            <button type="button" class="btn" id="preview">预览<i class="icon-eye-open"></i></button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <!-- END PAGE -->
</div>
<include file="Public:footer"/>
<script type="text/javascript" src="__TMPL__Public/plugins/bootstrap-fileupload/bootstrap-fileupload.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function () {
        $('#up_multiple').fileupload({
            url: 'index.php?m=Pig&c=Goods&a=uploadfiles',
            acceptFileTypes: /.+(jpg|gif|png|bmp)$/i,
            maxNumberOfFiles: 10,
            stop: function (){
                setTimeout(form_update, 500);
            }
        });
    });
</script>
<script type="text/javascript">
    jQuery(document).ready(function () {
        var tbody = '<div class="item clearfix"><input type="hidden" name="info_id[]" value="" /><span><input name="assistant[]" type="text" class="setInp" placeholder="规格名称" /></span><span><input name="sku[]" type="text" class="setInp" placeholder="商品编码" /></span><span><input name="sale_price[]" type="text" class="setInp" placeholder="零售价" /></span><span><input name="cost_price[]" type="text" class="setInp" placeholder="成本价" /></span><span><input name="distribution_price[]" type="text" class="setInp" placeholder="分销价" /></span><span><input name="stock[]" type="text" class="setInp" placeholder="库存" /></span><span><i class="icon-trash trash"></i></span></div></div>';
        var html = '<div class="ass"><div class="control-group"><div class="controls"><button id="add" type="button" class="btn green">添加规格 <i class="icon-save"></i></button></div></div><div class="controls"><div class="propertyTable"><div class="tabHead clearfix"><span>规格名称</span><span>商品编码</span><span>零售价</span><span>成本价</span><span>分销价</span><span>库存</span><span>操作</span></div><div class="tabBody"><div class="item clearfix"><input type="hidden" name="info_id[]" value="" /><span><input name="assistant[]" type="text" class="setInp" placeholder="规格名称" /></span><span><input name="sku[]" type="text" class="setInp" placeholder="商品编码" /></span><span><input name="sale_price[]" type="text" class="setInp" placeholder="零售价" /></span><span><input name="cost_price[]" type="text" class="setInp" placeholder="成本价" /></span><span><input name="distribution_price[]" type="text" class="setInp" placeholder="分销价" /></span><span><input name="stock[]" type="text" class="setInp" placeholder="库存" /></span><span><i class="icon-trash trash"></i></span></div></div></div></div></div>';

        /**
         * 删除规格
         */
         $('body').on('click','form .trash',function(){
            var Obj = $(this);
            /*判断规格数是否大于1*/
            var length = $('form .tabBody .item').length;
            if(length <= 1){
                custom_alert('至少保留一个规格');
                return false;
            }
            var info_id = Obj.closest('.item').find('[name^=info_id]').val()
            if(info_id){
                custom_confirm('确定删除该规格?',function(){
                    var del_ids = $('form input[name^=del_ids]').val();
                    if(del_ids){
                        del_ids += ',' + info_id;
                    }
                    $('form input[name^=del_ids]').val(del_ids);
                    Obj.closest('.item').remove();
                })
            }else{
                Obj.closest('.item').remove();
            }
         });

        /**
         * 添加规格
         */
         $('body').on('click','form #add',function(){
            $('form .tabBody').append(tbody);
         })

         /**
          * 切换规格
          */
          $('body').on('change','form input[name=type]:checked',function(){
                var Obj = $(this);
                if(Obj.val() == 0){
                    $('form .ass').remove();
                    $('form .sale_prices').show();
                    $('form .cost_prices').show();
                    $('form .distrubution_prices').show();
                    $('form .stocks').show();
                    $('form .skus').show();
                }else{
                    $('form .type').append(html);
                    $('form .sale_prices').hide();
                    $('form .cost_prices').hide();
                    $('form .distrubution_prices').hide();
                    $('form .stocks').hide();
                    $('form .skus').hide();
                }
          });
          var action = "{:ACTION_NAME}";
          var data = '{$html}';
          var type = {$info['type']?$info['type']:0};
          if(action == 'edit' && type == 1){
                $('form .sale_prices').hide();
                $('form .cost_prices').hide();
                $('form .distrubution_prices').hide();
                $('form .stocks').hide();
                $('form .skus').hide();
                $('form .type').append(data);
          }

          //预览
          $('body').on('click','#preview',function(){
                $('#container #edui272_body').trigger('click');
          })
          
          
    });
</script>
<!-- END JAVASCRIPTS -->
</body>
<!-- END BODY -->
</html>